<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Clojure documentation browser</title><style>
.library
{
  padding: 0.5em 0 0 0 
}
.all-libs-toggle,.library-contents-toggle
{
 font-size: small;
}
.all-libs-toggle a,.library-contents-toggle a
{
 color: white
}
.library-member-doc-whitespace
{
 white-space: pre
}
.library-member-source-toggle
{
  font-size: small;
  margin-top: 0.5em
}
.library-member-source
{
  display: none;
  border-left: solid lightblue 
}
.library-member-docs
{
  font-family:monospace
}
.library-member-arglists
{
  font-family: monospace
}
.library-member-type
{
  font-weight: bold; 
  font-size: small;
  font-style: italic;
  color: darkred
}
.lib-links
{
  margin: 0 0 1em 0
}

.lib-link-header
{
  color: white;
  background: darkgreen;
  width: 100%
}

.library-name 
{ 
  color: white;
  background: darkblue;
  width: 100%
}

.missing-library
{
  color: darkred; 
  margin: 0 0 1em 0 
}

.library-members
{
  list-style: none
}

.library-member-name
{
  font-weight: bold;
  font-size: 105%
}</style><script language="JavaScript" type="text/javascript"> // <![CDATA[

function getElem(id)
{
  if( document.getElementById )
  {
    return document.getElementById( id )
  }
  else if ( document.all )
  {
    return eval( 'document.all.' + id )
  }
  else
    return false;
}

function setDisplayStyle(id,displayStyle)
{
  var elem = getElem (id)
  if (elem)
  {
    elem.style.display = displayStyle
  }

}

function setLinkToggleText (id, text)
{
 var elem = getElem (id)
 if (elem)
 {
   elem.innerHTML = text
 }
}

function collapse(id)
{
  setDisplayStyle (id, 'none')
}

function expand (id)
{
  setDisplayStyle (id, 'block')
}

function toggleSource( id )
{
  toggle(id, 'linkto-' + id, 'Hide Source', 'Show Source')
}

function toggle(targetid, linkid, textWhenOpen, textWhenClosed)
{
  var elem = getElem (targetid)
  var link = getElem (linkid)

  if (elem && link)
  {
    var isOpen = false
    if (elem.style.display == '')
    {
      isOpen = link.innerHTML == textWhenOpen
    }
    else if( elem.style.display == 'block' )
    {
      isOpen = true
    }
    
    if (isOpen)
    {
      elem.style.display = 'none'
      link.innerHTML = textWhenClosed
    }
    else
    {
      elem.style.display = 'block'
      link.innerHTML = textWhenOpen
    }
  }
}

      //]]>
</script><script language="JavaScript" type="text/javascript">// <![CDATA[!
function expandAllNamespaces()
{
expand(&apos;library-contents-utils.misc&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.misc&apos;, &apos;-&apos;);
expand(&apos;library-contents-utils.readbinfile&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.readbinfile&apos;, &apos;-&apos;);
expand(&apos;library-contents-utils.readDB&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.readDB&apos;, &apos;-&apos;);
expand(&apos;library-contents-utils.writeDB&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.writeDB&apos;, &apos;-&apos;);
expand(&apos;library-contents-main.server&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.server&apos;, &apos;-&apos;);
expand(&apos;library-contents-main.client&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.client&apos;, &apos;-&apos;);
expand(&apos;library-contents-main.local&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.local&apos;, &apos;-&apos;);

}function collapseAllNamespaces()
{
collapse(&apos;library-contents-utils.misc&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.misc&apos;, &apos;+&apos;);
collapse(&apos;library-contents-utils.readbinfile&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.readbinfile&apos;, &apos;+&apos;);
collapse(&apos;library-contents-utils.readDB&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.readDB&apos;, &apos;+&apos;);
collapse(&apos;library-contents-utils.writeDB&apos;);
setLinkToggleText(&apos;library-contents-toggle-utils.writeDB&apos;, &apos;+&apos;);
collapse(&apos;library-contents-main.server&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.server&apos;, &apos;+&apos;);
collapse(&apos;library-contents-main.client&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.client&apos;, &apos;+&apos;);
collapse(&apos;library-contents-main.local&apos;);
setLinkToggleText(&apos;library-contents-toggle-main.local&apos;, &apos;+&apos;);

}
// ]]></script></head><body><div class="lib-links"><div class="lib-link-header">Namespaces<span class="all-libs-toggle"> [ <a href="javascript:expandAllNamespaces()">Expand All</a> ] [ <a href="javascript:collapseAllNamespaces()">Collapse All</a> ]</span></div><a class="lib-link" href="#library-main.client">main.client</a> <a class="lib-link" href="#library-main.local">main.local</a> <a class="lib-link" href="#library-main.server">main.server</a> <a class="lib-link" href="#library-utils.misc">utils.misc</a> <a class="lib-link" href="#library-utils.readDB">utils.readDB</a> <a class="lib-link" href="#library-utils.readbinfile">utils.readbinfile</a> <a class="lib-link" href="#library-utils.writeDB">utils.writeDB</a></div><div class="library"><a name="library-main.client"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-main.client" href="javascript:toggle(&apos;library-contents-main.client&apos;, &apos;library-contents-toggle-main.client&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>main.client</div><div class="library-contents" id="library-contents-main.client"><div class="library-member-links"><a class="lib-member-link" href="#member-main.client-*host*">*host*</a> <a class="lib-member-link" href="#member-main.client-*port*">*port*</a> <a class="lib-member-link" href="#member-main.client-con">con</a> <a class="lib-member-link" href="#member-main.client-disable-del-button">disable-del-button</a> <a class="lib-member-link" href="#member-main.client-disable-nav-buttons">disable-nav-buttons</a> <a class="lib-member-link" href="#member-main.client-get-selected-rows">get-selected-rows</a> <a class="lib-member-link" href="#member-main.client-refresh">refresh</a> <a class="lib-member-link" href="#member-main.client-update">update</a> <a class="lib-member-link" href="#member-main.client-window">window</a></div><ol class="library-members"><li class="library-member"><a name="member-main.client-*host*"/><dl class="library-member-table"><dt class="library-member-name">*host*</dt><dd><div class="library-member-info"><span class="library-member-type">var</span> <span class="library-member-arglists"></span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-*host*&apos;)" id="linkto-membersource-main.client-*host*">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-*host*"><pre>(def *host* &quot;localhost&quot;)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-*port*"/><dl class="library-member-table"><dt class="library-member-name">*port*</dt><dd><div class="library-member-info"><span class="library-member-type">var</span> <span class="library-member-arglists"></span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-*port*&apos;)" id="linkto-membersource-main.client-*port*">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-*port*"><pre>(def *port* 3003)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-con"/><dl class="library-member-table"><dt class="library-member-name">con</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([socket])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-con&apos;)" id="linkto-membersource-main.client-con">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-con"><pre>(defn con [socket]
  &quot;Establish a connection with a server socket&quot;
  (with-open [input (BufferedReader. (InputStreamReader. (.getInputStream socket)))
		      output (PrintWriter. (.getOutputStream socket))]    
		(let [rbf-output			(deserialize  (String. (.readLine input)))]
	     (.flush output)
           rbf-output
)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-disable-del-button"/><dl class="library-member-table"><dt class="library-member-name">disable-del-button</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([delB table])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Disables and enables the delete button depending on the number of rows in the page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-disable-del-button&apos;)" id="linkto-membersource-main.client-disable-del-button">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-disable-del-button"><pre>(defn disable-del-button
	&quot;Disables and enables the delete button depending on the number of rows in the page.&quot;
	[delB table]
	(if (zero? (.getRowCount (.getModel table)))
		(.setEnabled delB false)
		(.setEnabled delB true)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-disable-nav-buttons"/><dl class="library-member-table"><dt class="library-member-name">disable-nav-buttons</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([nextB prevB lastB firstB active-page rows-per-page key-count])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Disable and enables the navigation buttons depending on the actual page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-disable-nav-buttons&apos;)" id="linkto-membersource-main.client-disable-nav-buttons">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-disable-nav-buttons"><pre>(defn disable-nav-buttons
	&quot;Disable and enables the navigation buttons depending on the actual page.&quot;
	[nextB prevB lastB firstB active-page rows-per-page key-count]
	(let [last-page (ceil (/ (float key-count) rows-per-page))]
		(if (zero? key-count)
			(do
				(.setEnabled prevB false)
				(.setEnabled firstB false)
				(.setEnabled nextB false)
				(.setEnabled lastB false))
			(do
				(.setEnabled prevB true)
				(.setEnabled firstB true)
				(.setEnabled nextB true)
				(.setEnabled lastB true)
				(if (== active-page 1)
					(do
						(.setEnabled prevB false)
						(.setEnabled firstB false)))
				(if (&gt;= active-page last-page)
					(do
						(.setEnabled nextB false)
						(.setEnabled lastB false)))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-get-selected-rows"/><dl class="library-member-table"><dt class="library-member-name">get-selected-rows</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([table])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns a vector with the selected rows.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-get-selected-rows&apos;)" id="linkto-membersource-main.client-get-selected-rows">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-get-selected-rows"><pre>(defn get-selected-rows
	&quot;Returns a vector with the selected rows.&quot;
	[table]
	(let [num-rows (.getRowCount table)]
		(loop [index 0 v []]
			(if (== index num-rows)
				v
				(if (.isRowSelected table index)
					(recur (inc index) (conj v (.getValueAt table index 0)))
					(recur (inc index) v))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-refresh"/><dl class="library-member-table"><dt class="library-member-name">refresh</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-refresh&apos;)" id="linkto-membersource-main.client-refresh">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-refresh"><pre>(defn refresh []
  &quot;Updates the actual table in the GUI&quot;
  (let [socket (Socket. *host* *port*)]
    (with-open [input (BufferedReader. (InputStreamReader. (.getInputStream socket)))
                output (PrintWriter. (.getOutputStream socket))]
                (let [db  (deserialize (String. (.readLine input)))
                      records   (db :records)
                      ]
                      (println  records)
                      (.flush output)
                      records
                )
           )
    )
  )</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-update"/><dl class="library-member-table"><dt class="library-member-name">update</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([sock del ch add])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-update&apos;)" id="linkto-membersource-main.client-update">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-update"><pre>(defn update [sock del ch add]
  &quot;Uses socket connection to update the db&quot;
  (let [socket (Socket. *host* *port*)]
  (with-open [input (BufferedReader. (InputStreamReader. (.getInputStream socket)))
              output (PrintWriter. (.getOutputStream socket))]     
		 
         (let [sendinfo  (serialize {:delete @del :change @ch 
		                                          :new @add})]
		 (.println output sendinfo))
          (.flush output))  
))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.client-window"/><dl class="library-member-table"><dt class="library-member-name">window</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([title])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Displays a simple GUI window using tashe Swing API.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.client-window&apos;)" id="linkto-membersource-main.client-window">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.client-window"><pre>(defn window
  &quot;Displays a simple GUI window using tashe Swing API.&quot;
  [title]
  (let [frame				(JFrame. title)
		
        socket              (Socket. *host* *port*)
        
		mainPanel			(JPanel.)
		rightPanel			(JPanel.)
		navigationPanel		(JPanel.)
		navigationContent	(JPanel.)
		leftPanelAux		(JPanel.)
		leftPanel			(JPanel.)
		searchPanel			(JPanel.)
		searchContent		(JPanel.)
		showPanel			(JPanel.)
		showContent			(JPanel.)
		addPanel			(JPanel.)
		addContent			(JPanel.)

		logo				(JLabel. (ImageIcon. &quot;jemima.png&quot;))
		searchNaLa			(JLabel. &quot;Name&quot;)
		searchLoLa			(JLabel. &quot;Location&quot;)
		pending_changes     (JLabel. &quot; &quot;)      

		searchName			(JTextField. 15)
		searchLocation		(JTextField. 15)

		searchButton		(JButton. &quot;Query&quot;)
		clearButton			(JButton. &quot;Clear search&quot;)
		showButton			(JButton. &quot;Show rows(s)&quot;)
		addButton			(JButton. &quot;Add rows(s)&quot;)
		commitButton		(JButton. &quot;Save change(s)&quot;)
		nextButton			(JButton. &quot;&gt;&gt;&quot;)
		prevButton			(JButton. &quot;&lt;&lt;&quot;)
		lastButton			(JButton. &quot;&gt;|&quot;)
		firstButton			(JButton. &quot;|&lt;&quot;)
		deleteButton		(JButton. &quot;Delete row(s)&quot;)
		returnButton		(JButton. &quot;Return&quot;)
		refreshButton       (JButton. &quot;Refresh&quot;)
		
		rbf-output          (con socket)
		
		rows-per-page		10
		
		max-pk				(ref (rbf-output :max-pk))
		records				(ref (rbf-output :records))
		original-records	(ref (rbf-output :records))
		del-record-keys		(ref [])
		record-changes		(ref [])
		new-records			(ref (sorted-map))
		
		reckeys				(get-page (keys @records) (count (keys @records)) 1 rows-per-page)
		
		fields				(rbf-output :fields)
		field-names			(get-field-names fields)
		field-sizes			(get-field-sizes fields)
		fnames				(cons &quot;key&quot; field-names)
		
		
		page				(ref 1)
		max_page			(ref (int (ceil (/ (float (count (keys @records))) rows-per-page))))
        
		
			
		
		table-data			(to-array-2d (get-records @records fnames reckeys))
		table-columns		(into-array fnames)

		
		
		
		
		
		
		
		table-model			(DefaultTableModel. table-data table-columns)
		
		add-table-model		(DefaultTableModel. (into-array field-names) 1)
		
		
		
		table				(JTable. table-model)
		spane				(JScrollPane. table)
		pageLabel			(JLabel. (str @page &quot; / &quot; @max_page))
		
		next-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page inc))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		prev-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page dec))	
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		first-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page (fn[_] 1)))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		last-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		clear-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(.setText searchName &quot;&quot;)
									(.setText searchLocation &quot;&quot;)
									(dosync (alter page (fn[_] 1)))
									(let [na (.getText searchName) lo (.getText searchLocation)]
									(dosync (alter records (fn[_] (search (keys @original-records) @original-records na lo)))
									(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		search-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									;(println @max-pk)
									(dosync (alter page (fn[_] 1)))

									(let [na (.getText searchName) lo (.getText searchLocation)]
									(dosync (alter records (fn[_] (search (keys @original-records) @original-records na lo)))
									(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		delete-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(let [selected (get-selected-rows table)]
									(if (not (empty? selected))(do (dosync (alter records (fn[_] (del-records table @records selected)))
												(alter original-records (fn[_] (del-records table @original-records selected)))
												(alter del-record-keys (fn[x] (apply conj x selected)))
												(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page))))))))
										(println @del-record-keys)
										(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
										(change-page table-model @page rows-per-page @records fnames)
										(disable-del-button deleteButton table)
										(.setText pageLabel (str @page &quot; / &quot; @max_page)))
								        (.setText pending_changes &quot;Unsaved changes&quot;))
		                                )
		add-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(.setModel table add-table-model)
								(.setEnabled searchButton false)
								(.setEnabled addButton false)
								(.setEnabled commitButton false)
								(.setEnabled returnButton true)
								(.setEnabled deleteButton false)
								(.setEnabled nextButton false)
								(.setEnabled prevButton false)
								(.setEnabled lastButton false)
								(.setEnabled firstButton false)
								(.setEnabled refreshButton false)
								(.setEnabled clearButton false)
									))
		return-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(.setEnabled searchButton true)
								(.setEnabled addButton true)
								(.setEnabled returnButton false)
								(.setEnabled refreshButton true)
								(.setEnabled clearButton true)
								(.setText pending_changes &quot;Unsaved changes&quot;)
								(let [new-r (build-record-map (.getDataVector add-table-model) field-names (inc @max-pk))] 
								
								(dosync (alter records merge (new-r :map))
										(alter original-records merge (new-r :map))
										(alter max-pk (fn[_] (new-r :max-pk)))
										(alter new-records merge (new-r :map))
										(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
								(println @new-records)
								(.setRowCount add-table-model 0)
								(.setRowCount add-table-model 1)
								(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
								(disable-del-button deleteButton table)
								(change-page table-model @page rows-per-page @records fnames)
								(.setModel table table-model)
								(.setText pageLabel (str @page &quot; / &quot; @max_page))))
		m-click				(proxy [TableModelListener][]
								(tableChanged [event]
									(let [column (.getColumn event) row (.getFirstRow event)]
										(if (and (not (neg? column)) (not (neg? row)))
											(let [key (.getValueAt table row 0) content (.getValueAt table row column)]
												(dosync
													(alter record-changes conj [key column content])
													(alter records (fn[_] (change-record @records key column fnames content)))
													(alter original-records (fn[_] (change-record @original-records key column fnames content)))
												)
												(println @record-changes))))
								)
		                          )
		a-click				(proxy [TableModelListener][]
								(tableChanged [event]
								(if (and (zero? (.getColumn event)) (== (.getRowCount add-table-model) (inc (.getLastRow event))))
								(.addRow add-table-model (Vector.)))
									(.setText pending_changes &quot;Unsaved changes&quot;)))
		
		timerAction             (proxy [ActionListener][]
		                          (actionPerformed [event]
		                            
		                        (.setEnabled commitButton false))
		                        
		                        )
		
		timer                   (Timer. 5000 timerAction)
									
									
		commit-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(update socket del-record-keys record-changes new-records)
																(dosync (alter del-record-keys (fn[_] []))
										(alter record-changes (fn[_] []))
										(alter new-records (fn[_] (sorted-map))))
								(.setText pending_changes &quot; &quot;)
								(.setEnabled commitButton false)
								)
									
		)
		
		
		refresh-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								
								(let [refreshed (refresh)]
								
								(.restart timer)
								(.setEnabled commitButton true)
								(dosync (alter records (fn[_] refreshed))
										(alter original-records (fn[_] refreshed)))
								
								
								)
								
								(dosync (alter page (fn[_] 1))
								(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page))))))
								(.setText pageLabel (str @page &quot; / &quot; @max_page))
								(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
								(change-page table-model @page rows-per-page @records fnames)
								(disable-del-button deleteButton table)
								
								))
		]

	(.setLayout mainPanel (BorderLayout.))

	(.setLayout rightPanel (BorderLayout.))

	(.setLayout navigationPanel (BoxLayout. navigationPanel BoxLayout/Y_AXIS))
	(.setLayout navigationContent (BoxLayout. navigationContent BoxLayout/X_AXIS))

	(.setLayout leftPanelAux (FlowLayout.))
	(.setLayout leftPanel (BoxLayout. leftPanel BoxLayout/Y_AXIS))

	(.setLayout searchPanel (BoxLayout. searchPanel BoxLayout/Y_AXIS))
	(.setLayout searchContent (BoxLayout. searchContent BoxLayout/Y_AXIS))

	(.setLayout showPanel (BoxLayout. showPanel BoxLayout/Y_AXIS))
	(.setLayout showContent (BoxLayout. showContent BoxLayout/X_AXIS))

	(.setLayout addPanel (BoxLayout. addPanel BoxLayout/Y_AXIS))
	(.setLayout addContent (BoxLayout. addContent BoxLayout/Y_AXIS))

	;Setting Properties.

	(.setBorder mainPanel (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder navigationPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Navigate &amp; Delete&quot;))
	(.setBorder navigationContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder searchPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Search mode&quot;))
	(.setBorder searchContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder showPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Explore mode&quot;))
	(.setBorder showContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder addPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Add mode&quot;))
	(.setBorder addContent (BorderFactory/createEmptyBorder 10 10 10 10))

	(.setAlignmentX logo Component/CENTER_ALIGNMENT)

	(.setAlignmentX searchNaLa Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchLoLa Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchName Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchLocation Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchButton Component/CENTER_ALIGNMENT)
	(.setAlignmentX clearButton Component/CENTER_ALIGNMENT)
	
	(.setAlignmentX addButton Component/CENTER_ALIGNMENT)
	(.setAlignmentX returnButton Component/CENTER_ALIGNMENT)

	(.setAlignmentX commitButton Component/CENTER_ALIGNMENT)
	(.setAlignmentX refreshButton Component/CENTER_ALIGNMENT)
	
	(.setAlignmentX pending_changes Component/CENTER_ALIGNMENT)
	
	(.setEnabled searchButton true)
	(.setEnabled addButton true)
	(.setEnabled commitButton false)
	(.setEnabled returnButton false)
	(.setEnabled refreshButton true)
	(.setRepeats timer false)
	(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
	(disable-del-button deleteButton table)

	;Colors.

	(.setBackground showPanel Color/lightGray)
	(.setBackground showContent Color/lightGray)
	(.setBackground searchContent Color/lightGray)
	(.setBackground navigationContent Color/lightGray)
	(.setBackground leftPanelAux Color/lightGray)
	(.setBackground navigationPanel Color/lightGray)
	(.setBackground addContent Color/lightGray)
	(.setBackground leftPanel Color/lightGray)
	(.setBackground addPanel Color/lightGray)
	(.setBackground mainPanel Color/gray)
	(.setBackground searchPanel Color/lightGray)

	;Adding Components.

	(.add frame mainPanel)
		(.add mainPanel BorderLayout/CENTER rightPanel)
			(.add rightPanel BorderLayout/CENTER spane)
			(.add rightPanel BorderLayout/SOUTH navigationPanel)
				(.add navigationPanel navigationContent)
				(.add navigationContent firstButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 10 0)))
				(.add navigationContent prevButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 20 0)))
				(.add navigationContent pageLabel)
				(.add navigationContent (Box/createRigidArea (Dimension. 20 0)))
				(.add navigationContent nextButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 10 0)))
				(.add navigationContent lastButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 70 0)))
				(.add navigationContent deleteButton)
		(.add mainPanel BorderLayout/WEST leftPanelAux)
			(.add leftPanelAux leftPanel)
				(.add leftPanel logo)
				(.add leftPanel (Box/createRigidArea (Dimension. 0 10)))
				(.add leftPanel searchPanel)
					(.add searchContent searchNaLa)
					(.add searchContent searchName)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent searchLoLa)
					(.add searchContent searchLocation)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent searchButton)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent clearButton)
					(.add searchPanel searchContent)
				;(.add leftPanel showPanel)
					(.add showPanel (Box/createHorizontalGlue))
					(.add showPanel showContent)
						(.add showContent showButton)
					(.add showPanel (Box/createHorizontalGlue))
				(.add leftPanel addPanel)
					(.add addPanel (Box/createHorizontalGlue))
					(.add addPanel addContent)
						(.add addContent addButton)
						(.add addContent (Box/createRigidArea (Dimension. 0 10)))
						(.add addContent returnButton)
					(.add addPanel (Box/createHorizontalGlue))
				
			    (.add leftPanel (Box/createRigidArea (Dimension. 0 20)))
				(.add leftPanel refreshButton)
				(.add leftPanel (Box/createRigidArea (Dimension. 0 10)))
				(.add leftPanel pending_changes)
				(.add leftPanel (Box/createRigidArea (Dimension. 0 10)))
			    (.add leftPanel commitButton)
				

				
	(.addActionListener nextButton next-action)
	(.addActionListener prevButton prev-action)
	(.addActionListener firstButton first-action)
	(.addActionListener lastButton last-action)
	(.addActionListener searchButton search-action)
	(.addActionListener deleteButton delete-action)
	(.addActionListener commitButton commit-action)
	(.addActionListener addButton add-action)
	(.addActionListener returnButton return-action)
	(.addActionListener clearButton clear-action)
	(.addActionListener refreshButton refresh-action)
	(.addTableModelListener table-model m-click)
	(.addTableModelListener add-table-model a-click)
    (.setDefaultCloseOperation frame JFrame/DISPOSE_ON_CLOSE)
    (.pack frame)
    (.setVisible frame true)))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-main.local"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-main.local" href="javascript:toggle(&apos;library-contents-main.local&apos;, &apos;library-contents-toggle-main.local&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>main.local</div><div class="library-contents" id="library-contents-main.local"><div class="library-member-links"><a class="lib-member-link" href="#member-main.local-disable-del-button">disable-del-button</a> <a class="lib-member-link" href="#member-main.local-disable-nav-buttons">disable-nav-buttons</a> <a class="lib-member-link" href="#member-main.local-get-selected-rows">get-selected-rows</a> <a class="lib-member-link" href="#member-main.local-window">window</a></div><ol class="library-members"><li class="library-member"><a name="member-main.local-disable-del-button"/><dl class="library-member-table"><dt class="library-member-name">disable-del-button</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([delB table])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Disables and enables the delete button depending on the number of rows in the page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.local-disable-del-button&apos;)" id="linkto-membersource-main.local-disable-del-button">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.local-disable-del-button"><pre>(defn disable-del-button
	&quot;Disables and enables the delete button depending on the number of rows in the page.&quot;
	[delB table]
	(if (zero? (.getRowCount (.getModel table)))
		(.setEnabled delB false)
		(.setEnabled delB true)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.local-disable-nav-buttons"/><dl class="library-member-table"><dt class="library-member-name">disable-nav-buttons</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([nextB prevB lastB firstB active-page rows-per-page key-count])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Disable and enables the navigation buttons depending on the actual page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.local-disable-nav-buttons&apos;)" id="linkto-membersource-main.local-disable-nav-buttons">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.local-disable-nav-buttons"><pre>(defn disable-nav-buttons
	&quot;Disable and enables the navigation buttons depending on the actual page.&quot;
	[nextB prevB lastB firstB active-page rows-per-page key-count]
	(let [last-page (ceil (/ (float key-count) rows-per-page))]
		(if (zero? key-count)
			(do
				(.setEnabled prevB false)
				(.setEnabled firstB false)
				(.setEnabled nextB false)
				(.setEnabled lastB false))
			(do
				(.setEnabled prevB true)
				(.setEnabled firstB true)
				(.setEnabled nextB true)
				(.setEnabled lastB true)
				(if (== active-page 1)
					(do
						(.setEnabled prevB false)
						(.setEnabled firstB false)))
				(if (&gt;= active-page last-page)
					(do
						(.setEnabled nextB false)
						(.setEnabled lastB false)))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.local-get-selected-rows"/><dl class="library-member-table"><dt class="library-member-name">get-selected-rows</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([table])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns a vector with the selected rows.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.local-get-selected-rows&apos;)" id="linkto-membersource-main.local-get-selected-rows">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.local-get-selected-rows"><pre>(defn get-selected-rows
	&quot;Returns a vector with the selected rows.&quot;
	[table]
	(let [num-rows (.getRowCount table)]
		(loop [index 0 v []]
			(if (== index num-rows)
				v
				(if (.isRowSelected table index)
					(recur (inc index) (conj v (.getValueAt table index 0)))
					(recur (inc index) v))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.local-window"/><dl class="library-member-table"><dt class="library-member-name">window</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([title])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Displays a simple GUI window using the Swing API.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.local-window&apos;)" id="linkto-membersource-main.local-window">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.local-window"><pre>(defn window
  &quot;Displays a simple GUI window using the Swing API.&quot;
  [title]
  (let [frame				(JFrame. title)

		mainPanel			(JPanel.)
		rightPanel			(JPanel.)
		navigationPanel		(JPanel.)
		navigationContent	(JPanel.)
		leftPanelAux		(JPanel.)
		leftPanel			(JPanel.)
		searchPanel			(JPanel.)
		searchContent		(JPanel.)
		showPanel			(JPanel.)
		showContent			(JPanel.)
		addPanel			(JPanel.)
		addContent			(JPanel.)

		logo				(JLabel. (ImageIcon. &quot;jemima.png&quot;))
		searchNaLa			(JLabel. &quot;Name&quot;)
		searchLoLa			(JLabel. &quot;Location&quot;)


		searchName			(JTextField. 15)
		searchLocation		(JTextField. 15)

		searchButton		(JButton. &quot;Query&quot;)
		clearButton			(JButton. &quot;Clear search&quot;)
		showButton			(JButton. &quot;Show rows(s)&quot;)
		addButton			(JButton. &quot;Add rows(s)&quot;)
		commitButton		(JButton. &quot;Save change(s)&quot;)
		nextButton			(JButton. &quot;&gt;&gt;&quot;)
		prevButton			(JButton. &quot;&lt;&lt;&quot;)
		lastButton			(JButton. &quot;&gt;|&quot;)
		firstButton			(JButton. &quot;|&lt;&quot;)
		deleteButton		(JButton. &quot;Delete row(s)&quot;)
		returnButton		(JButton. &quot;Return&quot;)
		
		
		filename			&quot;db-1x2.db&quot;
		rbf-output			(read-bin-file filename)
		
		rows-per-page		10
		
		max-pk				(ref (rbf-output :max-pk))
		records				(ref (rbf-output :records))
		original-records	(ref (rbf-output :records))
		del-record-keys		(ref [])
		record-changes		(ref [])
		new-records			(ref (sorted-map))
		
		reckeys				(get-page (keys @records) (count (keys @records)) 1 rows-per-page)
		
		fields				(rbf-output :fields)
		field-names			(get-field-names fields)
		field-sizes			(get-field-sizes fields)
		fnames				(cons &quot;key&quot; field-names)
		
		
		page				(ref 1)
		max_page			(ref (int (ceil (/ (float (count (keys @records))) rows-per-page))))

		
		
		
		
		table-data			(to-array-2d (get-records @records fnames reckeys))
		table-columns		(into-array fnames)
		table-model			(DefaultTableModel. table-data table-columns)
		
		add-table-model		(DefaultTableModel. (into-array field-names) 1)
		
		
		
		table				(JTable. table-model)
		spane				(JScrollPane. table)
		
		pageLabel			(JLabel. (str @page &quot; / &quot; @max_page))
		
		next-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page inc))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		prev-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page dec))	
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		first-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page (fn[_] 1)))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		last-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(dosync (alter page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		clear-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(.setText searchName &quot;&quot;)
									(.setText searchLocation &quot;&quot;)
									(dosync (alter page (fn[_] 1)))
									(let [na (.getText searchName) lo (.getText searchLocation)]
									(dosync (alter records (fn[_] (search (keys @original-records) @original-records na lo)))
									(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		search-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									;(println @max-pk)
									(dosync (alter page (fn[_] 1)))

									(let [na (.getText searchName) lo (.getText searchLocation)]
									(dosync (alter records (fn[_] (search (keys @original-records) @original-records na lo)))
									(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
									(.setText pageLabel (str @page &quot; / &quot; @max_page))
									(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
									(change-page table-model @page rows-per-page @records fnames)
									(disable-del-button deleteButton table)))
		delete-action  		(proxy [ActionListener][]
								(actionPerformed [event]
									(let [selected (get-selected-rows table)]
									(if (not (empty? selected))(do (dosync (alter records (fn[_] (del-records table @records selected)))
												(alter original-records (fn[_] (del-records table @original-records selected)))
												(alter del-record-keys (fn[x] (apply conj x selected)))
												(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page))))))))
										(println @del-record-keys)
										(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
										(change-page table-model @page rows-per-page @records fnames)
										(disable-del-button deleteButton table)
										(.setText pageLabel (str @page &quot; / &quot; @max_page)))))
		add-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(.setModel table add-table-model)
								(.setEnabled searchButton false)
								(.setEnabled addButton false)
								(.setEnabled commitButton false)
								(.setEnabled returnButton true)
								(.setEnabled deleteButton false)
								(.setEnabled nextButton false)
								(.setEnabled prevButton false)
								(.setEnabled lastButton false)
								(.setEnabled firstButton false)
									))
		return-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(.setEnabled searchButton true)
								(.setEnabled addButton true)
								(.setEnabled commitButton true)
								(.setEnabled returnButton false)
								(let [new-r (build-record-map (.getDataVector add-table-model) field-names (inc @max-pk))] 
								
								(dosync (alter records merge (new-r :map))
										(alter original-records merge (new-r :map))
										(alter max-pk (fn[_] (new-r :max-pk)))
										(alter new-records merge (new-r :map))
										(alter max_page (fn[_] (int (ceil (/ (float (count (keys @records))) rows-per-page)))))))
								(println @new-records)
								(.setRowCount add-table-model 0)
								(.setRowCount add-table-model 1)
								(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
								(disable-del-button deleteButton table)
								(change-page table-model @page rows-per-page @records fnames)
								(.setModel table table-model)
								(.setText pageLabel (str @page &quot; / &quot; @max_page))))
		m-click				(proxy [TableModelListener][]
								(tableChanged [event]
									(let [column (.getColumn event) row (.getFirstRow event)]
										(if (and (not (neg? column)) (not (neg? row)))
											(let [key (.getValueAt table row 0) content (.getValueAt table row column)]
												(dosync
													(alter record-changes conj [key column content])
													(alter records (fn[_] (change-record @records key column fnames content)))
													(alter original-records (fn[_] (change-record @original-records key column fnames content)))
												)
												(println @record-changes))))))
		a-click				(proxy [TableModelListener][]
								(tableChanged [event]
								(if (and (zero? (.getColumn event)) (== (.getRowCount add-table-model) (inc (.getLastRow event))))
								(.addRow add-table-model (Vector.)))
									))
		commit-action  		(proxy [ActionListener][]
								(actionPerformed [event]
								(store-records @new-records filename field-names field-sizes)
								(set-record-db @record-changes filename 74 field-sizes)
								(del-record-db @del-record-keys filename 74 field-sizes)
								(dosync (alter del-record-keys (fn[_] []))
										(alter record-changes (fn[_] []))
										(alter new-records (fn[_] (sorted-map))))
									))
		]

	;Setting JPanels&apos; Layouts.
	(.setLayout mainPanel (BorderLayout.))

	(.setLayout rightPanel (BorderLayout.))

	(.setLayout navigationPanel (BoxLayout. navigationPanel BoxLayout/Y_AXIS))
	(.setLayout navigationContent (BoxLayout. navigationContent BoxLayout/X_AXIS))

	(.setLayout leftPanelAux (FlowLayout.))
	(.setLayout leftPanel (BoxLayout. leftPanel BoxLayout/Y_AXIS))

	(.setLayout searchPanel (BoxLayout. searchPanel BoxLayout/Y_AXIS))
	(.setLayout searchContent (BoxLayout. searchContent BoxLayout/Y_AXIS))

	(.setLayout showPanel (BoxLayout. showPanel BoxLayout/Y_AXIS))
	(.setLayout showContent (BoxLayout. showContent BoxLayout/X_AXIS))

	(.setLayout addPanel (BoxLayout. addPanel BoxLayout/Y_AXIS))
	(.setLayout addContent (BoxLayout. addContent BoxLayout/Y_AXIS))

	;Setting Properties.

	(.setBorder mainPanel (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder navigationPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Navigate &amp; Delete&quot;))
	(.setBorder navigationContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder searchPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Search mode&quot;))
	(.setBorder searchContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder showPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Explore mode&quot;))
	(.setBorder showContent (BorderFactory/createEmptyBorder 10 10 10 10))
	(.setBorder addPanel (BorderFactory/createTitledBorder (BorderFactory/createEtchedBorder EtchedBorder/LOWERED) &quot;Add mode&quot;))
	(.setBorder addContent (BorderFactory/createEmptyBorder 10 10 10 10))

	(.setAlignmentX logo Component/CENTER_ALIGNMENT)

	(.setAlignmentX searchNaLa Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchLoLa Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchName Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchLocation Component/CENTER_ALIGNMENT)
	(.setAlignmentX searchButton Component/CENTER_ALIGNMENT)
	(.setAlignmentX clearButton Component/CENTER_ALIGNMENT)
	
	(.setAlignmentX addButton Component/CENTER_ALIGNMENT)
	(.setAlignmentX returnButton Component/CENTER_ALIGNMENT)

	(.setAlignmentX commitButton Component/CENTER_ALIGNMENT)
	
	(.setEnabled searchButton true)
	(.setEnabled addButton true)
	(.setEnabled commitButton true)
	(.setEnabled returnButton false)
	(disable-nav-buttons nextButton prevButton lastButton firstButton @page rows-per-page (count (keys @records)))
	(disable-del-button deleteButton table)

	;Colors.

	(.setBackground showPanel Color/lightGray)
	(.setBackground showContent Color/lightGray)
	(.setBackground searchContent Color/lightGray)
	(.setBackground navigationContent Color/lightGray)
	(.setBackground leftPanelAux Color/lightGray)
	(.setBackground navigationPanel Color/lightGray)
	(.setBackground addContent Color/lightGray)
	(.setBackground leftPanel Color/lightGray)
	(.setBackground addPanel Color/lightGray)
	(.setBackground mainPanel Color/gray)
	(.setBackground searchPanel Color/lightGray)

	;Adding Components.

	(.add frame mainPanel)
		(.add mainPanel BorderLayout/CENTER rightPanel)
			(.add rightPanel BorderLayout/CENTER spane)
			(.add rightPanel BorderLayout/SOUTH navigationPanel)
				(.add navigationPanel navigationContent)
				(.add navigationContent firstButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 10 0)))
				(.add navigationContent prevButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 20 0)))
				(.add navigationContent pageLabel)
				(.add navigationContent (Box/createRigidArea (Dimension. 20 0)))
				(.add navigationContent nextButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 10 0)))
				(.add navigationContent lastButton)
				(.add navigationContent (Box/createRigidArea (Dimension. 70 0)))
				(.add navigationContent deleteButton)
		(.add mainPanel BorderLayout/WEST leftPanelAux)
			(.add leftPanelAux leftPanel)
				(.add leftPanel logo)
				(.add leftPanel (Box/createRigidArea (Dimension. 0 10)))
				(.add leftPanel searchPanel)
					(.add searchContent searchNaLa)
					(.add searchContent searchName)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent searchLoLa)
					(.add searchContent searchLocation)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent searchButton)
					(.add searchContent (Box/createRigidArea (Dimension. 0 10)))
					(.add searchContent clearButton)
					(.add searchPanel searchContent)
				;(.add leftPanel showPanel)
					(.add showPanel (Box/createHorizontalGlue))
					(.add showPanel showContent)
						(.add showContent showButton)
					(.add showPanel (Box/createHorizontalGlue))
				(.add leftPanel addPanel)
					(.add addPanel (Box/createHorizontalGlue))
					(.add addPanel addContent)
						(.add addContent addButton)
						(.add addContent (Box/createRigidArea (Dimension. 0 10)))
						(.add addContent returnButton)
					(.add addPanel (Box/createHorizontalGlue))
				(.add leftPanel (Box/createRigidArea (Dimension. 0 50)))
				(.add leftPanel commitButton)

				
	(.addActionListener nextButton next-action)
	(.addActionListener prevButton prev-action)
	(.addActionListener firstButton first-action)
	(.addActionListener lastButton last-action)
	(.addActionListener searchButton search-action)
	(.addActionListener deleteButton delete-action)
	(.addActionListener commitButton commit-action)
	(.addActionListener addButton add-action)
	(.addActionListener returnButton return-action)
	(.addActionListener clearButton clear-action)
	(.addTableModelListener table-model m-click)
	(.addTableModelListener add-table-model a-click)
    (.setDefaultCloseOperation frame JFrame/DISPOSE_ON_CLOSE)
    (.pack frame)
    (.setVisible frame true)))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-main.server"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-main.server" href="javascript:toggle(&apos;library-contents-main.server&apos;, &apos;library-contents-toggle-main.server&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>main.server</div><div class="library-contents" id="library-contents-main.server"><div class="library-member-links"><a class="lib-member-link" href="#member-main.server-*port*">*port*</a> <a class="lib-member-link" href="#member-main.server-accion-de-agente">accion-de-agente</a> <a class="lib-member-link" href="#member-main.server-auxiliar">auxiliar</a> <a class="lib-member-link" href="#member-main.server-sirve">sirve</a></div><ol class="library-members"><li class="library-member"><a name="member-main.server-*port*"/><dl class="library-member-table"><dt class="library-member-name">*port*</dt><dd><div class="library-member-info"><span class="library-member-type">var</span> <span class="library-member-arglists"></span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.server-*port*&apos;)" id="linkto-membersource-main.server-*port*">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.server-*port*"><pre>(def *port* 3003)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.server-accion-de-agente"/><dl class="library-member-table"><dt class="library-member-name">accion-de-agente</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([_ socket field-names filename field-sizes])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.server-accion-de-agente&apos;)" id="linkto-membersource-main.server-accion-de-agente">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.server-accion-de-agente"><pre>(defn accion-de-agente
	[_ socket field-names filename field-sizes]
	(with-open [input (BufferedReader. (InputStreamReader. (.getInputStream socket))) output (PrintWriter. (.getOutputStream socket))]
		(let [file (read-bin-file filename)
		          newinfo (serialize file)]
		      (.println output newinfo)
		      (.flush output))
		(let [update (.readLine input) puto (agent nil)]
			(clear-agent-errors puto)
			(send-off puto auxiliar update filename field-names field-sizes output)
	     )
	)
)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.server-auxiliar"/><dl class="library-member-table"><dt class="library-member-name">auxiliar</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([_ objeto filename field-names field-sizes output])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.server-auxiliar&apos;)" id="linkto-membersource-main.server-auxiliar">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.server-auxiliar"><pre>(defn auxiliar
	[_ objeto filename field-names field-sizes output]
	(let [	n			(read-string objeto)
			store    	(:new n)
			delete   	(:delete n)
			set-record	(:change n)] 
		(store-records store filename field-names field-sizes)
		(set-record-db set-record filename 74 field-sizes)
		(del-record-db delete filename 74 field-sizes)
	)
)</pre></div></div></dd></dl></li><li class="library-member"><a name="member-main.server-sirve"/><dl class="library-member-table"><dt class="library-member-name">sirve</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([])</span></div><div class="library-member-docs"/><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-main.server-sirve&apos;)" id="linkto-membersource-main.server-sirve">Show Source</a> ]</div><div class="library-member-source" id="membersource-main.server-sirve"><pre>(defn sirve
	[]  
	(let [nombre-archivo (first *command-line-args*)
		servidor		(ServerSocket. *port*)
		agente			(agent nil)
		filename		&quot;db-1x2.db&quot;
		rbf-output		(read-bin-file filename)		
		fields			(rbf-output :fields)
		field-names		(get-field-names fields)
		field-sizes		(get-field-sizes fields)]
(println &quot;7777777777777777777777777777777777777777777777777777777777777777777777777777777
77777777777777777777777777777777II?=~~~~:~~~~:~~~=II777777777777777777777777777
77777777777777777777777777+~~~::,,,,,,,,,,,,,,,,,,,:=~~=I7777777777777777777777
7777777777777777777777+~~~:,,,,::===+===~~~===+==~~:,:,,:=~I7777777777777777777
777777777777777777?~~::,,:~==~:......,:..........,,,~=+=:,,:~=I7777777777777777
777777777777777?~~,:,:~+:,........:,,.,......,,.,:,.,:,,,~+:,,~~I77777777777777
7777777777777?:~,,,~=,,..:::,.,.,~,,..,,....:...,,..,:.,.,.:=:,,~=7777777777777
77777777777+~::,==,,:,~.,...,...,....,..,....,,.....,....,...,+~,,~+77777777777
777777777+~::,~~.,.,,,:.....,...,,,...,,,.,,.,,,..,,......,,.:,,=,:~=7777777777
77777777=~,,==,.,:~:.,,,...,.,......,,,,,,,,,,,:,,,,:,~=.,,,,,,,==~,~=777777777
7777777~,,:=,:..,~:,...,......,,.,:::::::::::::::::::::.:,..,..,,I=~,~=77777777
77777I~,,=:....,,.,.,,,,......,,~===~~~~~::~::::::::::~=??..,...=II=:::=7777777
7777I~,,+.......,,..=:.,,,,,.,,~+++==~~~~~:~~::::::::::~=?~.,,,.II?I=:,=I777777
7777~,,=.,...::..,:,.,......,:~=++++==~~~~~~~~::::::,:::=+I....~??II?=,,~777777
777=,,=:,...,,,,,,,,,...,,.,,:~=+++++==~~~~~~~~~::::,:::~=+=..,I????I+~,~=77777
77I~,~:.......,,....,,,,,.,,:~~=+++=::::::~=~~::::::::,,,:~I.~I??????I=:,=I7777
77+,:=,..,.::,,.,......,,.,:~~~~=:,:~::,....:~~::::::,,,,,:=~II??????I+=,:=7777
77~,:~,.,,...,:,...~~:,..,::~~~~:~==~:::::::::::::::,,:=~,.:??????????I=,,~I777
7+:,+,..,.,~:..,...,,,,,.:::~~::~~~::,..,:,,:::::::,,:~~::.,~??????????+::~+777
7=:,+,,,..::,,.,....,,,,,::~~~::::.,,...,::,:~=~:::,,::::,,:~???????????~,:=777
7=,,=,,,.,,,..,.,::,.,,.,:~~~===~:,?,:.,I7=~=~~=~,,.,=:+.:+.=???????????=,,=777
7=,,=,.,,,,,:,,....,,,,,,:~~=====~~~:::::::~=~=+=:~,,~~~=~~++???????????=:,=777
7=,:~,....,,,,..,::,,,.,,::~===+===~~:~:~=+=:~~=+~,=.,:,:::::+????+?????=~,~777
7~,,~....,::,,,.:..,.,,,,:~~=++++==~~~::~~:::~=~==~:?.,.:~~~=+?++++++++++~,:I77
7=,:=.,,,,:,..,,,..,,,,,::~~~=++?+++=~~~~::,===+?=~:=?:.,,,:=+++++++++++?=,:I77
7=,,+...,,,,,...,,:,,,,,:::~~~==+??+=~::::,:=:,,~~::,,:.~=::::+?+++++++++=,:I77
7?:,+.,....,,...,:,,.,:,:~~~~~=====~~::::,=~:~=~::,.,,,:+==~::=++++++++++=,:777
77~,~:...,.,...,,,,,.~7I,~~~~~~~~~~::::,,=++~~~~~==::,,,++=~::=++++++++++=,:777
77=,:==,.,..,.,,,,,.,?++.::~~:::::::::,,~~==~===::~~:,,,~=~~::+++++++++++=,:777
77+:,=++::,,....,,,:..,.:::~~~::::::,,.~===~:::::::::::,,~~~,~?++++++++++~,:777
777=,:=?+:....,,::,.,...:~~~===~~::,,,~~:~?I777777777I=:,=~:~+++++++++++=:,=777
777=,,=+???~:,...,.,,,,.,:~~===~~~:,,,,~~=+==~~~~:::::,,:+=:++++++++++++=,~?777
7777~,:=?+++?==,.,,,,...,:~~===~~~~:,:=~:::::::::::,,,:::+~~++++++++++++:,~7777
7777~,,=++++++++:....,,..:::~==~~~~:~=++==~~=~~~~~~~~::::=~=+++++++++++=,~?7777
7777I~,:++++++++?+~~.,.,.,,,:~~~~~~~~+++=++++=~~~~~::,~~~~~+++++++++++=,:=77777
77777+~,=+++++++++++++=:.,,,::~=~~=======~~~~:::,,,,,:~::~+++++++++=+=::~777777
777777~,:=+++++++++++++++~,,:::~~~~==+==~~~~~::::,,,,::::=+=+++++++==:,~7777777
777777I~,,=++++++++++++=+7,,,:::~~:::~~~=====~~====~::::=+++++++++==,,~77777777
77777777~,,=+++++++++++=I7I,::::::~:::::~===+?I+==~~:::=+++++++++=~::=777777777
777777777+~,:=+++++++===+7777:::::::::::,::~~~~==~~~~:~=+++=++++==,,~=777777777
777777777 I~,,~==+=++++=I777777~:::::::::,,,:::::::~=+++=++++==~,,~=77777777777
77777777777+~,,~=+++==?77777I777=~~~::::::,,,,,,,:+=++=++===,,,~=77777777777777
777777777777I=:,,===+=I7I777777777+~::::,:,,,,,,,~++++===:,,,==7777777777777777
77777777777777+:,,,~==?777777777777I=~~:,,,,,,,:=+==~:,,:~=77777777777777777777
7777777777777777+:,,,,~~~==+IIII77777I=~~===+=::,,,:~=?777777777777777777777777
777777777777777777777+~,,,,,,,::~~~~~~~~~::,,,,,,:~==I7777777777777777777777777
77777777777777777777777777I++=~::::::::::~~~~=+I7777777777777777777777777777777
7777777777777777777777777777777777777777777777777777777777777777777777777777777&quot;)
	(loop []
		(println &quot;\n Serving Hotcakes and Petitons&quot;)      
		(let [socket (.accept servidor)]
			(clear-agent-errors agente)
			(send-off agente accion-de-agente socket field-names filename field-sizes) 
        (recur)))))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-utils.misc"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-utils.misc" href="javascript:toggle(&apos;library-contents-utils.misc&apos;, &apos;library-contents-toggle-utils.misc&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>utils.misc</div><div class="library-contents" id="library-contents-utils.misc"><div class="library-member-links"><a class="lib-member-link" href="#member-utils.misc-deserialize">deserialize</a> <a class="lib-member-link" href="#member-utils.misc-serialize">serialize</a></div><ol class="library-members"><li class="library-member"><a name="member-utils.misc-deserialize"/><dl class="library-member-table"><dt class="library-member-name">deserialize</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([s])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Interprets a string</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.misc-deserialize&apos;)" id="linkto-membersource-utils.misc-deserialize">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.misc-deserialize"><pre>(defn deserialize
	&quot;Interprets a string&quot;
	[s]
	(read-string s))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.misc-serialize"/><dl class="library-member-table"><dt class="library-member-name">serialize</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([o])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Serialize the specified clojure object and returns it.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.misc-serialize&apos;)" id="linkto-membersource-utils.misc-serialize">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.misc-serialize"><pre>(defn serialize
	&quot;Serialize the specified clojure object and returns it.&quot;
	[o]  
	(binding [*print-dup* true] (print-str o))
)</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-utils.readDB"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-utils.readDB" href="javascript:toggle(&apos;library-contents-utils.readDB&apos;, &apos;library-contents-toggle-utils.readDB&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>utils.readDB</div><div class="library-contents" id="library-contents-utils.readDB"><div class="library-member-links"><a class="lib-member-link" href="#member-utils.readDB-build-record-map">build-record-map</a> <a class="lib-member-link" href="#member-utils.readDB-change-page">change-page</a> <a class="lib-member-link" href="#member-utils.readDB-change-record">change-record</a> <a class="lib-member-link" href="#member-utils.readDB-del-records">del-records</a> <a class="lib-member-link" href="#member-utils.readDB-get-field-names">get-field-names</a> <a class="lib-member-link" href="#member-utils.readDB-get-field-sizes">get-field-sizes</a> <a class="lib-member-link" href="#member-utils.readDB-get-page">get-page</a> <a class="lib-member-link" href="#member-utils.readDB-get-records">get-records</a> <a class="lib-member-link" href="#member-utils.readDB-map-one-record">map-one-record</a> <a class="lib-member-link" href="#member-utils.readDB-search">search</a></div><ol class="library-members"><li class="library-member"><a name="member-utils.readDB-build-record-map"/><dl class="library-member-table"><dt class="library-member-name">build-record-map</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([vec-o-vec field-names row-count])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Builds a map containing all the records in a Vector.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-build-record-map&apos;)" id="linkto-membersource-utils.readDB-build-record-map">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-build-record-map"><pre>(defn build-record-map
	&quot;Builds a map containing all the records in a Vector.&quot;
	[vec-o-vec field-names row-count]
		(let [cloj-vec (vec (reverse vec-o-vec))]
			(loop [c1 cloj-vec nextkey row-count result {}]
				(if (empty? c1)
					{:map (dissoc result (keyword (.format (DecimalFormat. &quot;00000000&quot;) (dec nextkey)))) :max-pk (- nextkey 2)}
					(let [df (DecimalFormat. &quot;00000000&quot;)] (recur (pop c1) (inc nextkey) (assoc result (keyword (.format df nextkey)) (assoc (map-one-record (peek c1) field-names) (keyword &quot;key&quot;) nextkey))
								))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-change-page"/><dl class="library-member-table"><dt class="library-member-name">change-page</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([tableModel page n map-records fnames])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Sets the vector of a TableModel to a new vector containing the records at a certain page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-change-page&apos;)" id="linkto-membersource-utils.readDB-change-page">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-change-page"><pre>(defn change-page
	&quot;Sets the vector of a TableModel to a new vector containing the records at a certain page.&quot;
	[tableModel page n map-records fnames]
	(let [
		keys-map-records 	(keys map-records)
		reckeys 			(get-page keys-map-records (count keys-map-records) page n)
		table-data			(to-array-2d (get-records map-records fnames reckeys))
		table-columns		(into-array fnames)]
		(.setDataVector tableModel table-data table-columns)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-change-record"/><dl class="library-member-table"><dt class="library-member-name">change-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([map record-key field-index field-names change])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Changes records from memory.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-change-record&apos;)" id="linkto-membersource-utils.readDB-change-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-change-record"><pre>(defn change-record
	&quot;Changes records from memory.&quot;
	[map record-key field-index field-names change]
	(let [
		key (keyword (.format (DecimalFormat. &quot;00000000&quot;) record-key))
		record (map key)
		kfield (keyword (get (vec field-names) field-index))]
		(let [changed-record (assoc record kfield change)]
			(assoc map key changed-record))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-del-records"/><dl class="library-member-table"><dt class="library-member-name">del-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([table map key-vec])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Deletes records from memory.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-del-records&apos;)" id="linkto-membersource-utils.readDB-del-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-del-records"><pre>(defn del-records
	&quot;Deletes records from memory.&quot;
	[table map key-vec]
	(loop [kys key-vec m map]
	(if (empty? kys)
		m
		(let [key (keyword (.format (DecimalFormat. &quot;00000000&quot;) (peek kys)))]
			(recur (pop kys) (dissoc m key))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-get-field-names"/><dl class="library-member-table"><dt class="library-member-name">get-field-names</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the names of the DB&apos;s fields.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-get-field-names&apos;)" id="linkto-membersource-utils.readDB-get-field-names">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-get-field-names"><pre>(defn get-field-names
	&quot;Gets the names of the DB&apos;s fields.&quot;
	[fields]
	(for [field fields] (get field 0)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-get-field-sizes"/><dl class="library-member-table"><dt class="library-member-name">get-field-sizes</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Gets the names of the DB&apos;s sizes.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-get-field-sizes&apos;)" id="linkto-membersource-utils.readDB-get-field-sizes">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-get-field-sizes"><pre>(defn get-field-sizes
	&quot;Gets the names of the DB&apos;s sizes.&quot;
	[fields]
	(for [field fields] (get field 1)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-get-page"/><dl class="library-member-table"><dt class="library-member-name">get-page</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([KeyList KeyListSize P N])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Returns N records of the database belonging to P page.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-get-page&apos;)" id="linkto-membersource-utils.readDB-get-page">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-get-page"><pre>(defn get-page
	&quot;Returns N records of the database belonging to P page.&quot;
	[KeyList KeyListSize P N]
	(let [FirstKeyIndex (* (dec P) N) LastKeyIndex (* P N)]
		(if (&gt; LastKeyIndex KeyListSize)
			(subvec (vec KeyList) FirstKeyIndex KeyListSize)
			(subvec (vec KeyList) FirstKeyIndex LastKeyIndex))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-get-records"/><dl class="library-member-table"><dt class="library-member-name">get-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([records field-names reckeys])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Get the records with the specified keys in reckeys.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-get-records&apos;)" id="linkto-membersource-utils.readDB-get-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-get-records"><pre>(defn get-records
	&quot;Get the records with the specified keys in reckeys.&quot;
	[records field-names reckeys]
	(for [key reckeys]
		(for [field-name field-names]
			((records key) (keyword field-name)))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-map-one-record"/><dl class="library-member-table"><dt class="library-member-name">map-one-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([record-vec field-names])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Builds a map containing the fields and their respective data, of a record, from a Vector.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-map-one-record&apos;)" id="linkto-membersource-utils.readDB-map-one-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-map-one-record"><pre>(defn map-one-record
	&quot;Builds a map containing the fields and their respective data, of a record, from a Vector.&quot;
	[record-vec field-names]
		(loop [c1 (vec record-vec) c2 (vec field-names) result {}]
			(if (empty? c1)
				result
				(recur (pop c1) (pop c2) (assoc result (keyword (peek c2)) (peek c1))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readDB-search"/><dl class="library-member-table"><dt class="library-member-name">search</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([keyList dataB s-name s-location])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Searches records containing the specified values of name or/and location.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readDB-search&apos;)" id="linkto-membersource-utils.readDB-search">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readDB-search"><pre>(defn search
	&quot;Searches records containing the specified values of name or/and location.&quot;
	[keyList dataB s-name s-location]
	(let [is-name (empty? s-name) is-location (empty? s-location)]
		(loop [lst (vec keyList) map (sorted-map)]
			(if (empty? lst)
				map
				(let [record (dataB (peek lst))]
					(if (and (or is-name (= s-name (record :name))) (or is-location (= s-location (record :location))))
						(let [df (DecimalFormat. &quot;00000000&quot;)] (recur (pop lst) (assoc map (keyword (.format df (record :key))) record)))
						(recur (pop lst) map)))))))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-utils.readbinfile"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-utils.readbinfile" href="javascript:toggle(&apos;library-contents-utils.readbinfile&apos;, &apos;library-contents-toggle-utils.readbinfile&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>utils.readbinfile</div><div class="library-contents" id="library-contents-utils.readbinfile"><div class="library-member-links"><a class="lib-member-link" href="#member-utils.readbinfile-read-bin-file">read-bin-file</a> <a class="lib-member-link" href="#member-utils.readbinfile-read-fields-meta">read-fields-meta</a> <a class="lib-member-link" href="#member-utils.readbinfile-read-one-record">read-one-record</a> <a class="lib-member-link" href="#member-utils.readbinfile-read-records">read-records</a> <a class="lib-member-link" href="#member-utils.readbinfile-read-str-len">read-str-len</a></div><ol class="library-members"><li class="library-member"><a name="member-utils.readbinfile-read-bin-file"/><dl class="library-member-table"><dt class="library-member-name">read-bin-file</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file-name])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads a binary file and returns a vector with its information.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readbinfile-read-bin-file&apos;)" id="linkto-membersource-utils.readbinfile-read-bin-file">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readbinfile-read-bin-file"><pre>(defn read-bin-file
  &quot;Reads a binary file and returns a vector with its information.&quot;
  [file-name]
  (with-open [file (DataInputStream. (FileInputStream. file-name))]
    (let [magic-number (.readInt file)
          offset       (.readInt file)
          num-fields   (.readShort file)
          fields-meta  (read-fields-meta file num-fields)
          re-records      (read-records file fields-meta)
		  records		(re-records :records)
		  max-pk		(re-records :max-pk)]

      {:magic magic-number :offset offset :max-pk max-pk :num-fields num-fields 
       :fields fields-meta :records records})))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readbinfile-read-fields-meta"/><dl class="library-member-table"><dt class="library-member-name">read-fields-meta</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file num-fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads the meta-data of all the fields from the given file. You must specify </div><div class="library-member-doc-line">  the total number of fields.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readbinfile-read-fields-meta&apos;)" id="linkto-membersource-utils.readbinfile-read-fields-meta">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readbinfile-read-fields-meta"><pre>(defn read-fields-meta
  &quot;Reads the meta-data of all the fields from the given file. You must specify ...&quot;
  [file num-fields]
  (loop [n num-fields
         resultado []]
    (if (= n 0)
        resultado
        (let [name-len   (.readShort file)
              field-name (read-str-len file name-len)
              field-len  (.readShort file)]
             (recur (dec n) (conj resultado [field-name field-len]))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readbinfile-read-one-record"/><dl class="library-member-table"><dt class="library-member-name">read-one-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file fields key])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads one individual record from the given file. You must specify a vector </div><div class="library-member-doc-line">  with the fields&apos; meta-data.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readbinfile-read-one-record&apos;)" id="linkto-membersource-utils.readbinfile-read-one-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readbinfile-read-one-record"><pre>(defn read-one-record
  &quot;Reads one individual record from the given file. You must specify a vector ...&quot;
  [file fields key]
  (loop 
    [result {:key key :deleted (not (zero? (.readShort file)))}
     [[fname fsize] &amp; rest-fields] fields]
     (if fname
         (recur (assoc result (keyword fname) (.trim (read-str-len file fsize)))
                 rest-fields)
         result)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readbinfile-read-records"/><dl class="library-member-table"><dt class="library-member-name">read-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file fields])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Reads all the individual records of the file.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readbinfile-read-records&apos;)" id="linkto-membersource-utils.readbinfile-read-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readbinfile-read-records"><pre>(defn read-records
  &quot;Reads all the individual records of the file.&quot;
  [file fields]
  (loop 
    [result (sorted-map) key 1]
    (if (zero? (.available file))
        {:records result :max-pk (dec key)}
        (let [one-record (read-one-record file fields key)]
			(if (one-record :deleted)
				(recur result (inc key))
				(let [df (DecimalFormat. &quot;00000000&quot;)] (recur (assoc result (keyword (.format df key)) one-record) (inc key))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.readbinfile-read-str-len"/><dl class="library-member-table"><dt class="library-member-name">read-str-len</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([file n])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Read the next n bytes from file and create a string.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.readbinfile-read-str-len&apos;)" id="linkto-membersource-utils.readbinfile-read-str-len">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.readbinfile-read-str-len"><pre>(defn read-str-len
  &quot;Read the next n bytes from file and create a string.&quot;
  [file n]
  (let [barray (byte-array n)]
    (.readFully file barray)
    (String. barray)))</pre></div></div></dd></dl></li></ol></div></div><div class="library"><a name="library-utils.writeDB"/><div class="library-name"><span class="library-contents-toggle">[ <a id="library-contents-toggle-utils.writeDB" href="javascript:toggle(&apos;library-contents-utils.writeDB&apos;, &apos;library-contents-toggle-utils.writeDB&apos;, &apos;-&apos;, &apos;+&apos;)">-</a> ] </span>utils.writeDB</div><div class="library-contents" id="library-contents-utils.writeDB"><div class="library-member-links"><a class="lib-member-link" href="#member-utils.writeDB-build-db-record">build-db-record</a> <a class="lib-member-link" href="#member-utils.writeDB-del-record-db">del-record-db</a> <a class="lib-member-link" href="#member-utils.writeDB-pad-string">pad-string</a> <a class="lib-member-link" href="#member-utils.writeDB-set-record-db">set-record-db</a> <a class="lib-member-link" href="#member-utils.writeDB-store-records">store-records</a></div><ol class="library-members"><li class="library-member"><a name="member-utils.writeDB-build-db-record"/><dl class="library-member-table"><dt class="library-member-name">build-db-record</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([record field-names field-sizes])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Builds a record (string) for the DB with padding.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.writeDB-build-db-record&apos;)" id="linkto-membersource-utils.writeDB-build-db-record">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.writeDB-build-db-record"><pre>(defn build-db-record
	&quot;Builds a record (string) for the DB with padding.&quot;
	[record field-names field-sizes]
	(loop [fn (vec field-names) fs (vec field-sizes) string &quot;&quot;]
		(if (empty? fn)
			string
			(recur (pop fn) (pop fs) (str (pad-string (record (keyword (peek fn))) (peek fs)) string)))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.writeDB-del-record-db"/><dl class="library-member-table"><dt class="library-member-name">del-record-db</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([del-list filename offset field-sizes])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Deletes records from the Database file by setting the &apos;deleted&apos; flag to 0x8000.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.writeDB-del-record-db&apos;)" id="linkto-membersource-utils.writeDB-del-record-db">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.writeDB-del-record-db"><pre>(defn del-record-db
	&quot;Deletes records from the Database file by setting the &apos;deleted&apos; flag to 0x8000.&quot;
	[del-list filename offset field-sizes]
	(let [del-flag 128 file (RandomAccessFile. filename &quot;rw&quot;)]
		(loop [lst del-list]
			(if (empty? lst)
				(.close file)
				(let [seek-pos (+ offset (* (dec (peek lst))(apply + 2 field-sizes)))]
					(.seek file (long seek-pos))
					(.write file del-flag)
					(recur (pop lst)))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.writeDB-pad-string"/><dl class="library-member-table"><dt class="library-member-name">pad-string</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([temp-string size])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Pads the string to the specified size in bytes (with spaces).</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.writeDB-pad-string&apos;)" id="linkto-membersource-utils.writeDB-pad-string">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.writeDB-pad-string"><pre>(defn pad-string
	&quot;Pads the string to the specified size in bytes (with spaces).&quot;
	[temp-string size]
	(let [string (str temp-string &quot; &quot;) n (- size (.length string))]
		(.substring (apply str string (take n (repeat &quot; &quot;))) 0 size)))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.writeDB-set-record-db"/><dl class="library-member-table"><dt class="library-member-name">set-record-db</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([set-list filename offset field-sizes])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Changes fields from the records in the Database file.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.writeDB-set-record-db&apos;)" id="linkto-membersource-utils.writeDB-set-record-db">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.writeDB-set-record-db"><pre>(defn set-record-db
	&quot;Changes fields from the records in the Database file.&quot;
	[set-list filename offset field-sizes]
	(let [file (RandomAccessFile. filename &quot;rw&quot;)]
		(loop [lst set-list]
			(if (empty? lst)
				(.close file)
				(let [v (peek lst) rec-num (get v 0) f-num (get v 1) string (get v 2)]
					(let [seek-pos (+ offset (* (dec rec-num)(apply + 2 field-sizes)) (apply + 2 (take (dec f-num) field-sizes)))]
						(.seek file (long seek-pos))
						(.writeBytes file (pad-string string (get (vec field-sizes) (dec f-num))))
						(recur (pop lst))))))))</pre></div></div></dd></dl></li><li class="library-member"><a name="member-utils.writeDB-store-records"/><dl class="library-member-table"><dt class="library-member-name">store-records</dt><dd><div class="library-member-info"><span class="library-member-type">fn</span> <span class="library-member-arglists">([map filename field-names field-sizes])</span></div><div class="library-member-docs"><div class="library-member-doc-line">Stores a new record in the Database file.</div></div><div class="library-member-source-section"><div class="library-member-source-toggle">[ <a href="javascript:toggleSource(&apos;membersource-utils.writeDB-store-records&apos;)" id="linkto-membersource-utils.writeDB-store-records">Show Source</a> ]</div><div class="library-member-source" id="membersource-utils.writeDB-store-records"><pre>(defn store-records
	&quot;Stores a new record in the Database file.&quot;
	[map filename field-names field-sizes]
	(let [pks (keys map) db (FileOutputStream. filename true)]
		(loop [v1 (vec (reverse pks))]
			(if (empty? v1)
				(.close db)
				(do
					(.write db (. (String. (str (char 0) (char 0) (build-db-record (map (peek v1)) field-names field-sizes))) getBytes))
					(recur (pop v1)))))))</pre></div></div></dd></dl></li></ol></div></div></body></html>